function BInsertSort(arr) {
    for (let i = 2; i < arr.length; i++) {
        if (arr[i] < arr[i - 1]) {
            let j,
                low = 1,
                mid,
                hight = i - 1;

            arr[0] = arr[i];
            while (low <= hight) {
                mid = Math.floor((low + hight) / 2);
                if (arr[0] < arr[mid]) {
                    hight = mid - 1;
                } else {
                    low = mid + 1
                }
            }

            for (j = i - 1; j >= hight + 1; j--) {
                arr[j + 1] = arr[j];
            }

            arr[hight + 1] = arr[0];
        }
    }

    return arr.slice(1);
}

var arr = [-1, 49, 38, 65, 97, 76, 13, 27, 49]; // arr[0]闲置或者作为哨兵单元
arr = BInsertSort(arr);

console.log(arr)